package com.edu.utils;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.InputStream;
import java.util.Properties;

public class DBUtils {
    //连接池
    private static DataSource dataSource;

    static {
        try {
            //连接池 连接数据库 硬编码
            Properties properties = new Properties();
            InputStream in = DBUtils.class.getClassLoader().getResourceAsStream("druid.properties");
            properties.load(in);
            dataSource = DruidDataSourceFactory.createDataSource(properties);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //返回连接池
    public static DataSource getDataSource() {
        return dataSource;
    }

}
